#ifndef __MEASUREMENTFORMATTER_H__
#define __MEASUREMENTFORMATTER_H__

#include <iostream>
#include <UnitFormatter.h>

typedef int Amount;

template<class Unit>
    struct MeasurementFormatter
    {
        virtual void
        output(std::ostream&, const Amount& amount, const Unit & unit) const = 0;
    };

template<class Unit>
    struct MeasurementFormatterBySeq : MeasurementFormatter<Unit>
    {
        MeasurementFormatterBySeq()
        {
        }

        virtual void
        output(std::ostream&, const Amount& amount, const Unit & unit) const;

    private:

    };

template<class Unit>
    struct MeasurementFormatterByBaseUnit : MeasurementFormatter<Unit>
    {
        MeasurementFormatterByBaseUnit()
        {
        }

        virtual void
        output(std::ostream&, const Amount& amount, const Unit & unit) const;

    private:

    };

template<class Unit>
    void
    MeasurementFormatterBySeq<Unit>::output(std::ostream& out, const Amount& amount,
            const Unit & unit) const
    {
        UnitFormatter<Unit> formatter(out, unit.convertToBaseUnit(amount));

        if (amount == 0)
        {
            outputInBaseUnit(formatter);
        }
        else
        {
            outputInUnitSeq(formatter);
        }
    }

template<class Unit>
    void
    MeasurementFormatterByBaseUnit<Unit>::output(std::ostream& out,
            const Amount& amount, const Unit & unit) const
    {
        UnitFormatter<Unit> formatter(out, unit.convertToBaseUnit(amount));

        outputInBaseUnit(formatter);
    }

#endif

